/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <iostream>
#include <algorithm>
#include <forward_list>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <set>
#include <string>
using namespace std;
class Prime
{
public:
    bool operator()(int element)
    {
        if (element<=1)
        {
            return false;
        }
        else
        {
            int upper_factor=floor(sqrt(element));
            for (int i=2;i<=upper_factor ;++i )
            {
                if (0==element%i)
                {
                    return false;
                }
            }
            return true;
        }
    }
};
void show(auto &container)
{
    for(auto elem:container)
    {
        cout << elem << " ";
    }
    cout << endl;
}
void findAllInt(auto &container,int integer)
{
    auto iter=find(container.begin(),container.end(),integer);
    if (iter!=container.end())
    {
        do
        {
            cout << "find "<<integer << endl;
            ++iter;
        }
        while ((iter=find(iter,container.end(),integer))!=container.end());
    }
    else
    {
        cout << "Don't find "<<integer << endl;
    }
    cout << endl;
}
void findAllIntIf(auto &container,auto predicate)
{
    auto iter=find_if(container.begin(),container.end(),predicate);
    if (iter!=container.end())
    {
        do
        {
            cout << "find "<<*iter << endl;
            ++iter;
        }
        while ((iter=find_if(iter,container.end(),predicate))!=container.end());
    }
    else
    {
        cout << "Don't find "<< endl;
    }
    cout << endl;
}
int main_27()
{
    srand((unsigned int)time(nullptr));
    forward_list<int> for_list;
    set<int> int_set;
    int random_int;
    for (int i=0; i<10 ; ++i )
    {
        random_int=rand()%50;
        for_list.push_front(random_int);
        int_set.insert(random_int);
    }
    show(for_list);
    random_int=rand()%50;
    findAllInt(for_list,random_int);
    findAllIntIf(for_list,not1(bind2nd(modulus<int>(),2)));// odd
    findAllIntIf(for_list,bind2nd(modulus<int>(),2));//even
    findAllIntIf(for_list,bind2nd(greater<int>(),4));// greater than 4
    findAllIntIf(for_list,Prime());//prime number
    auto iter=int_set.find(random_int);
    if (iter!=int_set.end())
    {
        cout << "find "<<random_int<<" in set." << endl;
    }
    else
    {
        cout << "Don't find "<<random_int<<" in set." << endl;
    }
    string str="2563491540@qq.com@163.com";
    char c='@';
    string::size_type pos=str.find(c);
    if (pos!=string::npos)
    {
        do
        {
            cout << "find "<<c<<" in the position "<<pos<< endl;
            ++pos;
        } while ((pos=str.find(c,pos))!=string::npos);
    }
    else
    {
        cout << "Don't find "<<c<< endl;
    }
    return 0;
}
